<?php

require('config.php');

//Vérifier que l'utilisateur est connecté

$page = new rootLayoutPage();
$page->setBaliseTitle('inscription_balise');
$page->setDescription('inscription_description');


$xml = tmxTranslate('newsletter.xml', REP_XLAT_TEMPLATE);
$xml_subject = tmxTranslate('subject.mail.xml', REP_XLAT_MAIL);
//-- menu Left show products--------------------------------//
$menu = new layoutMenuLeft();
$menuPage = new layoutMenuPage();
$menu->pushMenu($menuPage);
$page->setMenuPage($menu);

$tpl_file='newsletter.tpl';
$newsletter = new flyLayout(REP_TPL . $tpl_file);
$newsletter->start();
	if(isset($_POST['email'])){
		$email = addslashes($_POST['email']);
		if(isValidEmail($email)){
			if(!modelUser::existNewsletter($email)){
				modelUser::insertEmailInNewsletter($email);

				$mail = new flyLayout(REP_MAIL.'newsletter.mail.tpl');
					$mail->start();
					$mail->setVariable('mail_utilisateur', $email);
					$mail->stop();

					$subject = $xml_subject['newsletter'];

					if(STATUS_EMAIL == 0) {
		        		echo $mail;
		        	}elseif(STATUS_EMAIL == 1) {
		        		monsterMail(MAIL_NEWSLETTER, $subject, $mail);
		        	}else {
		        		echo $mail;
		        		monsterMail(MAIL_NEWSLETTER, $subject, $mail);
		        	}

				$newsletter->showBlock('success');
			}else
				 $newsletter->showBlock('exist');
		}else
				$newsletter->showBlock('invalid');
}

$newsletter->stop();
$page->setBody($newsletter);
$page->display();

?>